import 'package:flutter/material.dart';
import 'package:love_app/common/su.dart';
import 'package:love_app/pages/love_record/love_record_ui/center_item.dart';
import 'package:love_app/providers/love_record_provider.dart';
import 'package:love_app/routes/application.dart';
import 'package:love_app/routes/fluro_convert_util.dart';
import 'package:provider/provider.dart';

// import 'love_record_ui/centent.dart';
import 'love_record_ui/test_content.dart';

// 恋爱记录页面
class LoveRecord extends StatefulWidget {

  @override
  _LoveRecordState createState() => _LoveRecordState();
}

class _LoveRecordState extends State<LoveRecord> {

  LoveRecordProvider _loveRecordProvider;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _loveRecordProvider =
        Provider.of<LoveRecordProvider>(context, listen: true);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _myAppbar(context),
      // backgroundColor: Colors.blueGrey[100],
      body: _centent(),
    );
  }

  // 内容
  Widget _centent() {
    return Column(
      children: <Widget>[
        CenterItem(),
        // Centent(),
        Expanded(
          // flex: 2,
          child: Centent(),
        ),
      ],
    );
    // return Centent();
  }

  // 自定义appBar
  Widget _myAppbar(BuildContext context) {
    return AppBar(
      title: InkWell(
        onDoubleTap: () {
          _loveRecordProvider.offset = 0.0;
          setState(() {});
        },
        child: Text(
          '恋爱记录',
          style: Su().textStyle(Colors.black, 36),
        ),
      ),
      backgroundColor: Colors.white,
      elevation: 0, // 取消阴影
      // leading: ,
      centerTitle: true,
      leading: _leadingIcon(),
      actions: _acitonIcon(context),
    );
  }

  // leading按钮
  Widget _leadingIcon() {
    return IconButton(
      icon: Icon(
        Icons.arrow_back_ios,
        size: Su().w(35),
        color: Color.fromRGBO(238, 135, 176, 1),
      ),
      onPressed: () {
        Navigator.pop(context);
      },
    );
  }

  // actions内容
  List<Widget> _acitonIcon(BuildContext context) {
    return <Widget>[
      IconButton(
        icon: Icon(
          Icons.edit,
          size: Su().w(35),
          color: Color.fromRGBO(238, 135, 176, 1),
        ),
        onPressed: () {
          final String apiPath = "love_log"; // 发表恋人动态
          final String appBarTitle =
              FluroConvertUtils.fluroCnParamsEncode("发表恋爱记录");
          Application.router.navigateTo(context,
              "/addLoveDynamic?apiPath=$apiPath&appBarTitle=$appBarTitle");
        },
      ),
    ];
  }
}
